package com.stuinfo;

import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.plaf.nimbus.NimbusLookAndFeel;

public class MainInfo extends JFrame implements ActionListener {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private SelectWay selectway;
	private InsertShow insertshow;
	private DeleteShow deleteshow;
	private UpdateShow updateshow;
	public static Connection conn;

	public MainInfo() {

		setTitle("学生信息");
		setSize(200, 400);
		setVisible(true);
		setLocation(300, 100);
		setDefaultCloseOperation(EXIT_ON_CLOSE);
		setLayout(new GridBagLayout());

		String[] jb = { "查询", "插入", "修改", "删除" };
		GridBagConstraints gbc = new GridBagConstraints();
		for (int i = 0; i < jb.length; i++) {

			JButton mb = new JButton(jb[i]);
			gbc.gridx = 0;
			gbc.gridy = i;
			gbc.insets = new Insets(20, 20, 20, 20);
			add(mb, gbc);
			mb.addActionListener(this);

		}

		selectway = new SelectWay(this, true);
		selectway.setSize(800, 400);
		selectway.setLocation(200, 100);

		updateshow = new UpdateShow(this, true);
		updateshow.setSize(800, 400);
		updateshow.setLocation(200, 100);

		insertshow = new InsertShow(this, true);
		insertshow.setSize(800, 500);
		insertshow.setLocation(200, 100);

		deleteshow = new DeleteShow(this, true);
		deleteshow.setSize(800, 400);
		deleteshow.setLocation(200, 100);

	}

	public static void main(String[] args) {
		
		
		
		try {
			UIManager.setLookAndFeel(new NimbusLookAndFeel());
		} catch (UnsupportedLookAndFeelException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}

		try {
			Class.forName("oracle.jdbc.driver.OracleDriver");
			System.out.println("驱动加载成功");
			conn = DriverManager.getConnection("jdbc:oracle:thin:@127.0.0.1:1521:xe", "zhangbiao", "sys");
			System.out.println("连接数据库");
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		SwingUtilities.invokeLater(new Runnable() {

			@Override
			public void run() {
				new MainInfo();

			}
		});

	}

	public static Connection getConn() {
		return conn;
	}

	public static void setConn(Connection conn) {
		MainInfo.conn = conn;
	}

	@Override
	public void actionPerformed(ActionEvent e) {

		String cmd = e.getActionCommand();
		switch (cmd) {
		case "查询":
			selectway.setVisible(true);
			break;

		case "插入":
			insertshow.setVisible(true);
			break;

		case "修改":
			updateshow.setVisible(true);
			break;

		case "删除":
			deleteshow.setVisible(true);
			break;
		}

	}

}
